package Template5::Saver;

sub new($)
{
	my $class = shift;
	my $availattrs = shift;

	$this = {'availattrs' => $availattrs};
	$this->{'availattrs'}->{'path'} = 1;

	return bless($this, $class);
};

sub starttag($)
{
	my $this = shift;
	my $node = shift;

  my @attrsnames = $node->all_external_attr_names();
  my $retval     = sprintf('<%s', $node->tag());
  
  foreach my $attrname (reverse($node->all_external_attr_names()))
  {
  	if(exists($this->{'availattrs'}->{$attrname}))
  	{
  		if($this->{'availattrs'}->{$attrname})
  		{
  			$retval.= sprintf(' %s="%s"', $attrname, $node->attr($attrname));
  		}
  		else
  		{
  			$retval.= sprintf(' %s', $attrname);		
  		};
  	}
  	elsif($attrname =~ /^xmlns\:/)
  	{
  		$retval.= sprintf(' %s="%s"', $attrname, $node->attr($attrname));
  	};
  };
  
  $retval .= $node->content_list()?'>':' />';  
  return $retval;
};

sub endtag($)
{
	my $this = shift;
	my $node = shift;
	
	return $node->content_list()?sprintf('</%s>', $node->tag()):'';
};

1;

